package com.f5.management.service.impl;

import com.f5.management.dao.TollDAO;
import com.f5.management.dao.TollDetailDAO;
import com.f5.management.entity.Member;
import com.f5.management.entity.Toll;
import com.f5.management.entity.TollDetail;
import com.f5.management.service.TollDetailService;
import com.f5.management.utils.DeviceUtil;
import com.f5.management.utils.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TollDetailServiceImpl implements TollDetailService {

    @Autowired
    private TollDetailDAO tollDetailDAO;

    @Override
    public PageResult<List<TollDetail>> findByPage(int page, int size) {
        PageResult<List<TollDetail>> result = new PageResult<List<TollDetail>>();
        Page<TollDetail> startPage = PageHelper.startPage(page, size);
        List<TollDetail> tollDetails = tollDetailDAO.findByPage();
        result.setCurrentPage(page);
        result.setSize(size);
        result.setTotal(startPage.getTotal());
        result.setTotalPage(startPage.getPages());
        result.setData(tollDetails);

        System.out.println(tollDetails);
        return result;
    }

    @Override
    public boolean add(TollDetail tollDetail) {
        //自动生成编号
        return tollDetailDAO.insert(tollDetail) > 0 ? true : false;
    }

    @Override
    public List<Member> findMemberByName() {
        return tollDetailDAO.findMemberByName();
    }

    @Override
    public int findCidByName(String communityName){

        return tollDetailDAO.findCidByName(communityName);
    }

    @Override
    public TollDetail findById(int id) {

        return tollDetailDAO.findById(id);
    }

    @Override
    public boolean updateInfo(TollDetail tollDetail) {


        return tollDetailDAO.updateInfo(tollDetail) > 0 ? true : false;
    }

    @Override
    public boolean delInfo(int id) {
        return tollDetailDAO.delInfo(id) > 0 ? true : false;
    }
}
